$(function () {
	vm.getKuaibao();
    vm.getStudents();
});

var vm = new Vue({
    el: '#mapp',
    data: {
        studentName: '叮当',
        gradeLabel: '初中三年级',
        announcement: '',
        bsnFirstStudent: {},
        bsnStudentList: {},
        bsnMentor: {},
        bsnZhidaoList: {},
		pageParams: {
			limit: "100",
			page: "1"
		},
		executeCount: 0
    },
    methods: {
    	getKuaibao: function() {
			$.get(ajaxServerUrlG("bsnKb/lastKb"), function(r){
				if (r.code == 0) {
                	vm.announcement = r.kb;
				}
            });
    	},
    	getStudents: function() {
			$.get(ajaxServerUrlG("bsnstudent/infoByLoginParent"), function(r){
				if (r.code == 0) {
                	vm.bsnStudentList = r.page.list;
                	vm.bsnFirstStudent = vm.bsnStudentList[0];
				}
            });
    	},
		//获取导师信息
		getMentor: function(mentorId){
			if (StringUtils.isEmpty(mentorId)) {
				$("#mentor-section").hide();
				return;
			};
			
			$.get(ajaxServerUrlG("bsnmentor/info/" + mentorId), function(r){
				if (r.code == 0) {
                	vm.bsnMentor = r.bsnMentor;
                	$("#mentor-section").show();
				}
            });
		},
		getGoutongZhidao: function(studentId) {
			vm.pageParams.studentIds = [studentId];
            $.ajax({
                type: "POST",
                url: ajaxServerUrlG("bsngoutongzhidao/listByStudents"),
                contentType: "application/json",
                data: JSON.stringify(vm.pageParams),
                success: function (r) {
                    if (r.code === 0) {
                        vm.bsnZhidaoList = r.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });
		},
		//用vue的事件代替jquery的事件
		// $('#firstTab a').click(function(e) {
			// e.preventDefault();  //阻止a链接的跳转行为
			// $(this).tab('show'); //显示当前选中的链接及关联的content
			// vm.refreshData($(this).attr('id'));
		// });
		tabClick: function(e, id, mentorId) {
			$("#" + id).tab('show'); //显示当前选中的链接及关联的content, bootstrap的方法
			vm.getMentor(mentorId);
			console.log(id);
			vm.getGoutongZhidao(id);
		},
		gotoZhiDaoInfo: function(zhidaoId) {
			location.href = "parentZhiDaoInfo.html?id=" + zhidaoId;
		},
		gotoMentorInfo: function(mentorId) {
			location.href = "comMentorInfo.html?id=" + mentorId;
		},
		preView: function(jianliurl) {
			if (StringUtils.isEmpty(jianliurl)) {
				return;
			}
			console.log("附件=" + jianliurl);
			var uploadUrl = getDownFileUrl(jianliurl);
			if (/iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase())) {
				openFileView(uploadUrl);
			} else {
				window.jsInvoke.openFileView(uploadUrl);
			}
		}
    },
	filters: {
		/*过滤并替换头像 */
		imgFilter: function (imgUrl, xingb) {
			if (StringUtils.isNotEmpty(imgUrl)) {
				return imgUrl;
			}
			if (xingb == "男") {
				return "images/man@2x.png";
			} else {
				return "images/woman@2x.png";
			}
		}
	},
	//生命周期函数，数据更新到el完成之后事件
	updated: function () {
		// console.group('updated 更新完成状态===============》');
		// console.log("%c%s", "color:red","el     : " + this.$el);
		// console.log(this.$el);
		// console.log(this);
		// console.log("%c%s", "color:red","data   : " + this.$data); 
		// console.log("%c%s", "color:red","message: " + this.message);
		
		// $('#firstTab a').click(function(e) {
			// e.preventDefault(); //阻止a链接的跳转行为
			// $(this).tab('show'); //显示当前选中的链接及关联的content
		// });
		if (StringUtils.isEmpty(this.bsnFirstStudent.id)) {
			return;
		}		    	
    	//每次数据绑定后都会触发此方法，只在首次click;
    	if (this.executeCount  == 0) {

    		this.executeCount++;
    		//此方法不生效
	    	// $("#" + vm.bsnFirstStudent.id).click();
	    	document.getElementById(this.bsnFirstStudent.id).click();
    	}
	}
});

